var router = require("express").Router();

var Student = require("../modules/db/student");
//显示
router.get("/show", (req, res) => {
  Student.find((err, user) => {
    res.json({
      error: 0,
      user: user,
    });
  });
});
//删除
router.get("/delete", (req, res) => {
    Student.deleteOne(req.query, (err) => {
        res.json({ error: 0, txt: "删除成功" });
  });
});


//页码
router.get("/find", function (req, res) {
  // console.log(req.query);
  var page = req.query * 1 || 1;
  Student.find()
    .limit(5)
    .skip(5 * (page - 1))
    .exec(function (err, user) {
      Student.countDocuments((err, count) => {
        var allpages = Math.ceil(count / 5);
        // console.log(user);
        res.json({ 
          error: 0,
           txt: "成功",
           page:page-0,
           allpages:allpages,
           user:user

           });
        
      });
    });
});





module.exports = router;
